<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCouponRecordsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('coupon_records', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('user_id')->index();
            $table->unsignedInteger('coupon_id');
            $table->string('code')->unique()->nullable();
            $table->timestamp('used_at')->nullable()->comment('使用时间');
            $table->string('status')->default('unused')->comment('状态 unused未使用 ，used 使用，expired 过期');;
            $table->dateTime('expired_at')->comment('用户领取后的过期时间');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('coupon_records');
    }
}
